package cn.net.lwj.common.model;

import cn.net.lwj.common.util.XmlXStreamUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("serial")
public class XmlResult implements Serializable {

    private Integer flag;
    private String exception;

    public final static Integer SUCSESS = 1;
    public final static Integer ERROR = 0;

    public XmlResult() {
    }

    public XmlResult(Integer flag, String exception) {
        this.flag = flag;
        this.exception = exception;
    }

    public static String toXmlString(Integer flag, String exception) {
        XmlResult xmlResult = new XmlResult(flag, exception);
        return XmlXStreamUtils.objectToXml(xmlResult, aliasInfo);
    }

    public static String responseSuccess(String exception) {
        XmlResult xmlResult = new XmlResult(SUCSESS, exception);
        return XmlXStreamUtils.objectToXml(xmlResult, aliasInfo);
    }

    public static String responseError(String exception) {
        XmlResult xmlResult = new XmlResult(ERROR, exception);
        return XmlXStreamUtils.objectToXml(xmlResult, aliasInfo);
    }

    public final static Map<String,Class<?>> aliasInfo = new HashMap() {{
        put("result", XmlResult.class);
    }};

    public Integer getFlag() {
        return flag;
    }

    public void setFlag(Integer flag) {
        this.flag = flag;
    }

    public String getException() {
        return exception;
    }

    public void setException(String exception) {
        this.exception = exception;
    }

    @Override
    public String toString() {
        return "XmlResult{" +
                "flag=" + flag +
                ", exception='" + exception + '\'' +
                '}';
    }
}
